package eclipse.lib.graphics.primitives;
import javax.media.opengl.*;
import eclipse.lib.*;
import eclipse.lib.graphics.shaders.GLColor;
import eclipse.util.io.*;
public class GLPrimitiveObject 
{
	public int vertexCount;
	public Position[] vertexData;
	public GLColor[]  vertexColor;
	public GLPrimitiveObject()
	{}
	public GLPrimitiveObject(PropertyFile pFile)
	{
		vertexCount = Integer.parseInt(pFile.readProperty("OBJECT", "VERTS"));
		vertexData  = new Position[vertexCount];
		vertexColor = new GLColor[vertexCount];
		for(int i = 0; i < vertexCount; i++)
		{
			float x = Float.parseFloat((pFile.readProperty("OBJECT", "VERT" + i, "X")));
			float y = Float.parseFloat((pFile.readProperty("OBJECT", "VERT" + i, "Y")));
			float z = Float.parseFloat((pFile.readProperty("OBJECT", "VERT" + i, "Z")));
			float a = Float.parseFloat((pFile.readProperty("OBJECT", "VERT" + i, "A")));
			float r = Float.parseFloat((pFile.readProperty("OBJECT", "VERT" + i, "R")));
			float g = Float.parseFloat((pFile.readProperty("OBJECT", "VERT" + i, "G")));
			float b = Float.parseFloat((pFile.readProperty("OBJECT", "VERT" + i, "B")));
			
			vertexData[i] = new Position(x, y, z);
			vertexColor[i]= new GLColor(a, r, g, b);
		}
	}
	public void draw(GL gl)
	{
		gl.glBegin(GL.GL_TRIANGLES);		
		for(int i = 0; i < vertexCount; i++)
		{
			gl.glColor4f(
					vertexColor[i].getRed(),
					vertexColor[i].getBlue(),
					vertexColor[i].getGreen(),
					vertexColor[i].getAlpha());
			gl.glVertex3f(			
					vertexData[i].x,
					vertexData[i].y,
					vertexData[i].z);			
			
		}
		gl.glEnd();
	}
}
